package com.cloudwise.controller;

import com.cloudwise.entity.TblGood;
import com.cloudwise.service.TblGoodService;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商品表(TblGood)表控制层
 *
 * @author
 * @since 2022-03-14 16:18:41
 */
@Controller
@RequestMapping("good")
public class TblGoodController {
    /**
     * 服务对象
     */
    @Resource
    private TblGoodService tblGoodService;


    @RequestMapping("toCart")
    public String toCart(){
        return "mycart";
    }



    /**
     * @create by: Teacher陈（86521760@qq.com）
     * @description: 查询所有的商品
     * @create time: 2022/3/14 16:22
     * @return
     */
    @GetMapping("findAll")
    @ResponseBody
    public List<TblGood> findAllGoods(){
        return tblGoodService.findAllGoods();
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<TblGood> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.tblGoodService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param tblGood 实体
     * @return 新增结果
     */
    @PostMapping("addGood")
    @ResponseBody
    public ResponseEntity<TblGood> add( @RequestBody  TblGood tblGood) {
        return ResponseEntity.ok(this.tblGoodService.insert(tblGood));
    }

    /**
     * 编辑数据
     *
     * @param tblGood 实体
     * @return 编辑结果
     */

    @PutMapping
    public ResponseEntity<TblGood> edit(TblGood tblGood) {
        return ResponseEntity.ok(this.tblGoodService.update(tblGood));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("deleteById")
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.tblGoodService.deleteById(id));
    }

}

